﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class Controls_Hotel_ctrHotelBooking : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetLable();
            ValidateControl();
            BindDataToDDLFullNameTitle();
            BindDataToDay();
         
            BindDataToYear1();
            BindDataCountry();
            BindDataToDDLRoomType();
            BindDataToPaymentDropdown();
        }
    }
    private void BindDataToDDLFullNameTitle()
    {
        ListItem item = new ListItem("Mr.", "Mr.", true);
        ddlTitle.Items.Add(item);
        ListItem item1 = new ListItem("Miss.", "Miss.", true);
        ddlTitle.Items.Add(item1);
        ListItem item2 = new ListItem("Mrs.", "Mrs.", true);
        ddlTitle.Items.Add(item2);
        ListItem item3 = new ListItem("Ms.", "Ms.", true);
        ddlTitle.Items.Add(item3);
        ListItem item4 = new ListItem("Dr.", "Dr.", true);
        ddlTitle.Items.Add(item4);
    }
    private void BindDataToDay()
    {
        for (int i = 0; i < 31; i++)
        {
            ListItem item;
            if ((i + 1) < 10)
                item = new ListItem((i + 1).ToString(), "0" + (i + 1).ToString(), true);
            else
                item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlCheckIn1.Items.Add(item);
            ddlCheckOut1.Items.Add(item);
        }
    }
    private void ValidateControl()
    {
        rfvContactEmail.ErrorMessage = MultipleLanguage.CONTACT_EMAIL_EMPTY[nCurrentLang - 1];
        rfvContactFullname.ErrorMessage = MessagesValidate.Setting_FULLNAME_EMPTY[nCurrentLang - 1];
        rfvContactPhone.ErrorMessage = MessagesValidate.BASKET_TEL_EMPTY[nCurrentLang - 1];
        revEmail.ErrorMessage = MessagesValidate.Setting_EMAIL_WRONG[nCurrentLang - 1];
        revNumberOfExtraBed.ErrorMessage = MessagesValidate.NUMBEROFEXTRABED_NUMBER[nCurrentLang - 1];
        revNumberOfRoom.ErrorMessage = MessagesValidate.NUMBEROFROOM_NUMBER[nCurrentLang - 1];
    }
    //private void BindDataToMonth()
    //{
    //    for (int i = 0; i < 12; i++)
    //    {
    //        ListItem item;
    //        if ((i + 1) < 10)
    //            item = new ListItem((i + 1).ToString(), "0" + (i + 1).ToString(), true);
    //        else
    //            item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
    //        ddlCheckOut2.Items.Add(item);
    //        ddlCheckIn2.Items.Add(item);
    //    }
    //}
    private void BindDataToYear1()
    {
        for (int i = 2011; i < 2020; i++)
        {
            ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlCheckIn3.Items.Add(item);
            ddlCheckOut3.Items.Add(item);
        }
    }
    private void BindDataCountry()
    {
        DataTable dtbCustomerCountry = new DataTable();
        CustomerCountry objCustomerCountry = new CustomerCountry();
        dtbCustomerCountry = objCustomerCountry.GetALL();

        ddlCountry.DataSource = dtbCustomerCountry;
        ddlCountry.DataValueField = "CountryID";
        switch (nCurrentLang)
        {
            case 1:
                ddlCountry.DataTextField = "CountryName1";
                break;
            case 2:
                ddlCountry.DataTextField = "CountryName2";
                break;
            case 3:
                ddlCountry.DataTextField = "CountryName3";
                break;
        }
        ddlCountry.DataBind();
    }
    private void BindDataToDDLRoomType()
    {
        RoomType obj = new RoomType();
        DataTable dtb = new DataTable();

        dtb = obj.GetAll();
        ddlRoomClass.DataSource = dtb;
        int nCurrentLang = Support.GetCurrentLanguage();
        switch (nCurrentLang)
        {
            case 1:
                ddlRoomClass.DataTextField = "Description1";
                break;
            case 2:
                ddlRoomClass.DataTextField = "Description2";
                break;
            case 3:
                ddlRoomClass.DataTextField = "Description3";
                break;
        }
        ddlRoomClass.DataValueField = "RoomType";
        ddlRoomClass.DataBind();
    }
    private void SetLable()
    {
        lblBooking.Text = MultipleLanguage.HOTELBOOKING[nCurrentLang - 1];

        lblCheckIn.Text = MultipleLanguage.LBL_CHECKIN[nCurrentLang - 1];
        lblCheckOut.Text = MultipleLanguage.LBL_CHECKOUT[nCurrentLang - 1];
        lblCountry.Text = MultipleLanguage.LBL_COUNTRY[nCurrentLang - 1];
        lblEmail.Text = MultipleLanguage.EMAIL[nCurrentLang - 1];
        lblFullName.Text = MultipleLanguage.LBL_FULLNAME[nCurrentLang - 1];
        lblHotel.Text = MultipleLanguage.HOTEL[nCurrentLang - 1];
        lblNumberOfRoom.Text = MultipleLanguage.LBL_NUMBEROFROOM[nCurrentLang - 1];
        lblNumberOfExtraBed.Text = MultipleLanguage.LBL_NUMBEROFEXTRABED[nCurrentLang - 1];
        lblOtherRequest.Text = MultipleLanguage.LBL_OTHERREQUEST[nCurrentLang - 1];
        lblPhone.Text = MultipleLanguage.TELEPHONE[nCurrentLang - 1];
        lblRoomClass.Text = MultipleLanguage.LBL_ROOMTYPE[nCurrentLang - 1];
        lblTitle.Text = MultipleLanguage.LBL_FULLNAMETILE[nCurrentLang - 1];
        lblPayment.Text = MultipleLanguage.LBL_PAYMENT[nCurrentLang - 1];

        int nHotelID = ConvertData.ConvertToInt(Request.QueryString[Config.HOTELID]);
        Hotel objHotel = new Hotel();
        objHotel.LoadById(nHotelID);
        switch(nCurrentLang)
        {
            case 1:
                lblValHoltel.Text = objHotel.Data.Title1;
                break;
            case 2:
                lblValHoltel.Text = objHotel.Data.Title2;
                break;
            case 3:
                lblValHoltel.Text = objHotel.Data.Title3;
                break;
        }
    }
    private void LoadHotelName(int HotelID)
    {
        Hotel objHotel = new Hotel();
        if (HotelID > 0)
        {
            objHotel.LoadById(HotelID);
        }
        switch (nCurrentLang)
        {
            case 1:
                lblHotel.Text = objHotel.Data.Title1;
                break;
            case 2:
                lblHotel.Text = objHotel.Data.Title2;
                break;
            case 3:
                lblHotel.Text = objHotel.Data.Title3;
                break;
        }
    }
    private void BindDataToPaymentDropdown()
    {
        DataTable dtbPayment = new DataTable();
        Payment objPayment = new Payment();
        dtbPayment = objPayment.GetAll();

        ddlPayment.DataSource = dtbPayment;
        ddlPayment.DataValueField = "PaymentID";
        ddlPayment.DataTextField = "Description";
        ddlPayment.DataBind();
    }
    
  
    private void reSetLable()
    {
        txtEmail.Text = "";
        txtFullName.Text = "";
        txtNumberOfExtraBed.Text = "";
        txtNumberOfRoom.Text = "";
        txtOtherRequest.Text = "";
        txtPhone.Text = "";
    }
    private eHotelBooking setData(int HotelID)
    {
        eHotelBooking objHotelBk = new eHotelBooking();
        objHotelBk.BookingDate = ConvertData.ConvertDatetimeToInt(DateTime.Today);
        objHotelBk.CheckIn = ConvertData.ConvertDateStringToInt(ddlCheckIn1.Text + "/" + ddlCheckIn2.SelectedValue + "/" + ddlCheckIn3.SelectedValue);
        objHotelBk.CheckOut = ConvertData.ConvertDateStringToInt(ddlCheckOut1.Text + "/" + ddlCheckOut2.SelectedValue + "/" + ddlCheckOut3.SelectedValue);
        objHotelBk.CountryID = ConvertData.ConvertToInt(ddlCountry.SelectedValue);
        objHotelBk.Email = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtEmail.Text));
        objHotelBk.FullName = ConvertData.ConvertToString(ddlTitle.SelectedValue) + " " + ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName.Text));
        objHotelBk.HotelID = HotelID;
        objHotelBk.NumberOfExtraBed = ConvertData.ConvertToInt(txtNumberOfExtraBed);
        objHotelBk.NumberOfRoom = ConvertData.ConvertToInt(txtNumberOfRoom);
        objHotelBk.Phone = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPhone.Text));
        objHotelBk.QuestionsAndComments = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtOtherRequest.Text));
        objHotelBk.RoomClass = ConvertData.ConvertToInt(ddlRoomClass.SelectedValue);
        objHotelBk.Status = 0;
        objHotelBk.PaymentID = ConvertData.ConvertToInt(ddlPayment.SelectedValue);
        return objHotelBk;
    }
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        HotelBooking objHotelBooking = new HotelBooking();
        int nHotelID = ConvertData.ConvertToInt(Request.QueryString[Config.HOTELID]);

        objHotelBooking.Data = this.setData(nHotelID);
        int nResult = objHotelBooking.Insert();
        reSetLable();

        if (nResult > 0)
        {
            Alert1.ShowMessage(1, MessagesAlert.BOOKTOUR_SUCCESSFUL[nCurrentLang - 1]);
            reSetLable();
        }
        else
        {
            Alert1.ShowMessage(1, MessagesAlert.UPDATE_UNSUCCESSFUL[nCurrentLang - 1]);
        }
    }
}